<?php
/*  psnRemoteFileReader
    @version 0.9.2
 
    Copyright (C) 2011  Vespo Marco | http://thelairofthemad.altervista.org/

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

-----------------------------------------------------------------------------------------------*/
include_once 'remoteLoginFileReader.class.php';

class psnRemoteFileReader extends remoteLoginFileReader{

	private $sessionId;

	public function __construct($sessionId){		
		parent::__construct("","","https://secure.eu.playstation.com/ajax/mypsn/friend/presence","https://secure.eu.playstation.com/sign-in/confirmation/?sessionId=","supercalifragilistichespiralidoso",1);
		$this->sessionId=$sessionId;		
	}
	
	public function getData(){
		 $cc = curl_init();
		 if($this->log){
		 	$fp = fopen('curl_log_data.txt','a+');
		 	curl_setopt ($cc, CURLOPT_STDERR, $fp);
		 }
		
		 curl_setopt_array($cc,array(
			CURLOPT_URL => $this->dataURL,
			CURLOPT_POST => 0,
			CURLOPT_RETURNTRANSFER => 1,
			CURLOPT_FOLLOWLOCATION => 1,
			CURLOPT_USERAGENT => $this->getRandomUserAgent(),
			CURLOPT_SSL_VERIFYPEER => 0,
			CURLOPT_REFERER => $this->dataURL,
			CURLOPT_VERBOSE => 1
		));
		 
		 curl_setopt ($cc, CURLOPT_COOKIEFILE, $this->cookiePath);
		 $this->data = curl_exec($cc);
		 curl_close($cc);
		 $this->xml = simplexml_load_string($this->data);
		 if($this->log)
		 	fclose($fp);
		 if(!$this->xml)
		     return false;
		 else
		     return $this->xml;
	}

	public function login()
	{	
		if($this->log){
			$f = fopen('curl_log.txt','a+');
			curl_setopt ($c, CURLOPT_STDERR, $f);
		}
		$c = curl_init($this->loginURL."".$this->sessionId);
		curl_setopt_array($c,array(
			CURLOPT_SSL_VERIFYPEER => 0,
			CURLOPT_SSL_VERIFYHOST => 0,
			CURLOPT_RETURNTRANSFER => 1,
			CURLOPT_HTTPGET => 1,
			CURLOPT_COOKIEFILE => $this->cookiePath,
			CURLOPT_COOKIEJAR => $this->cookiePath,
			CURLOPT_VERBOSE => 1
		));
		$d = curl_exec($c);
		curl_close($c);
		if($this->log)
			fclose($f);
		return $c;
	} 
	
	public function getSessionId(){return $this->sessionId;}
	
	public function setSessionId($sessionId){$this->sessionId=$sessionId;}
}
?>
